// 导入koa
const Koa = require('koa')
const Router=require('koa-Router')
const Mock=require('mockjs')
const path=require('path')
const fs=require('fs')
const bodyparser=require('koa-bodyparser')
// 创建koa服务器
const app = new Koa()
const router = new Router()
// 导入cors跨域
const cors = require('koa-cors')
// 导入获取post数据
const {koaBody} = require('koa-body')

// 使用中间件
app.use(koaBody())
app.use(cors())
app.use(bodyparser())
app.use(router)





// 三年人员去向接口
router.get('/api/xiang',ctx=>{
     const data=Mock.mock({
            "xAxis":[
                {
                    type:'value',
                    boundaryGap:[0,0.01],
                    axisLabel:{
                        textStyle:{
                            fontSize:18,
                            color:'#D5CBE8'
                        }
                    },
                    axisLine:{
                        lineStyle:{
                            color:'#DDD'
                        }
                    },
                    splitLine:{
                        lineStyle:{
                            type:'dashed',
                            color:'#DDD'
                        }
                    }
                    
                }
            ],
            yAxis:[
                {
                    type:'category',
                    name:'',
                    data:['上海','天津','重庆','广东','浙江'],
                    axisLabel:{
                        textStyle:{
                            fontSize:12,
                            color:'#D5CBE8'
                        }
                    },
                    axisLine:{
                        show:false
                    },
                    splitLine:{
                        show:false
                    }
                }
            ],
            series:[
                {
                    data:['@integer(100,2000)','@integer(500,5500)','@integer(600,6200)','@integer(700,7400)','@integer(8000,8400)','@integer(1000,12000)']
                },
                    {
                    data:['@integer(10000,20000)','@integer(520,5500)','@integer(700,9200)','@integer(10000,11000)','@integer(8000,8400)','@integer(1000,2000)']
                },
                    {
                    data:['@integer(200,2100)','@integer(3000,5500)','@integer(1770,7200)','@integer(1111,8100)','@integer(4000,4400)','@integer(3240,5800)']
                },
            ]
     })
     ctx.body={
        code:200,
        msg:'调取成功',
        data
     }
})


// 三年人员毕业工作状态
router.get('/api/work',ctx=>{
     const data=Mock.mock({
            "list":[
            {value:Mock.mock('@integer(150,300)'), name: '社会组织'},
                {value:Mock.mock('@integer(300,400)'),name:'事业单位'},
                {value:Mock.mock('@integer(300,590)'),name:'工商企业登记注册'},
                {value:Mock.mock('@integer(200,250)'),name:'登记注册'}
            ]
     })
     ctx.body={
        code:200,
        msg:'调取成功',
        data
     }
})

// 毕业生流向城市
router.get('/api/city',ctx=>{
    const data=Mock.mock({
        "salvProValue":[
            Mock.mock('@integer(250,300)'),
            Mock.mock('@integer(180,190)'),
            Mock.mock('@integer(150,160)'),
            Mock.mock('@integer(140,150)'),
            Mock.mock('@integer(120,140)'),
            Mock.mock('@integer(110,100)'),
            Mock.mock('@integer(80,90)'),
            Mock.mock('@integer(70,80)'),
            Mock.mock('@integer(50,60)'),
            Mock.mock('@integer(130,150)')
        ]
    })
    ctx.body={
        code:200,
        msg:"请求成功",
        data
    }
})

// 第二页毕业薪资分布
router.get('/api/salary',ctx=>{
    const data=Mock.mock({
            backgroundColor:'#05014c',
            color:['#01c3d5','#e46666','#a05ffd','#FFDB5C'],
            tooltip:{
                trigger:'item',
                formatter:'{a} <br/>{b} : {c}%'
            },
            legend:{
                data:['30k+','20k~30k','15k~20k','10k~15k','10人及以下'],
                textStyle:{
                    color:'#fff'
                }
            },
            series:[
                {
                    name:'预期',
                    type:'funnel',
                    left:'10%',
                    width:'80%',
                    label:{
                        normal:{
                            formatter:'{b}'
                        },
                        emphasis:{
                            position:'inside',
                            formatter:'{b}: {c}%'
                        }
                    },
                    labelLine:{
                        normal:{
                            show:false
                        }
                    },
                    itemStyle:{
                        normal:{
                            opacity:0.7
                        }
                    },
                    data:[
                        {value:'@integer(60,70)',name:'28人'},
                        {value:'@integer(40,50)',name:'4人'},
                        {value:'@integer(20,30)',name:'3人'},
                        {value:'@integer(80,90)',name:'3人'},
                        {value:'@integer(100,120)',name:'2人'}
                    ]
                },
                {
                    name:'实际',
                    type:'funnel',
                    left:'10%',
                    width:'80%',
                    maxSize:'80%',
                    label:{
                        normal:{
                            position:'inside',
                            formatter:'{c}%',
                            textStyle:{
                                color:'#777'
                            }
                        },
                        emphasis:{
                            position:'inside',
                            formatter:'{b}实际: {c}%'
                        }
                    },
                    itemStyle:{
                        normal:{
                            opacity:0.4,
                            borderColor:'#fff',
                            borderWidth:2
                        }
                    },
                    data:[
                        {value:'@integer(20,30)',name:'30k+'},
                        {value:'@integer(5,10)',name:'20k~30k'},
                        {value:'@integer(0,5)',name:'15k~20k'},
                        {value:'@integer(40,50)',name:'10k~15k'},
                        {value:'@integer(70,80)',name:'10人及以下'}
                    ]
                }
            ]
    })
    ctx.body={
        code:200,
        msg:'请求成功',
        data
    }
})


//第二页 中间下面的表格总统计
router.get('/api/worktab',ctx=>{
    const data=Mock.mock({
        "header":['城市','就职企业','岗位','薪资'],
        "list":[
            ['@city','百度','前端工程师','@integer(6,20)k'],
            ['@city','字节跳动','大数据','@integer(6,20)k'],
            ['@city','滴滴出行','软件开发','@integer(6,20)k'],
            ['@city','美团','UI设计','@integer(6,20)k'],
            ['@city','腾讯','硬件测试','@integer(6,20)k']
        ]
    })
    ctx.body={
        code:200,
        msg:'请求成功',
        data
    }
})


// 第四页场地使用
router.get('/api/site',ctx=>{
    const data=Mock.mock({
        gird:{
            top:'15%',
            right:'10%',
            left:'10%',
            bottom:'12%'
        },
        xAxis:[{
            type:'category',
            axisLine:{
              lineStyle:{
                color:'#fff'
              }  
            },
            data:['宿舍楼','教学楼','实验楼','超市','武德楼']
        }],
        yAxis:[{
            min:0,
            max:100,
            axisLine:{
                lineStyle:{
                    color:'rgba(107,107,107,0.37)'
                }
            },
            axisTick:{
                show:false
            },
            splitLine:{
                lineStyle:{
                    color:'rgba(131,101,101,0.2)',
                    type:'dashed'
                }
            }
        }],
        series:[
            {
                data:['@integer(30,40)','@integer(50,60)','@integer(25,30)','@integer(60,70)','@integer(25,30)']
            }
        ]
    })
    ctx.body={
        code:200,
        msg:'接口调用成功',
        data
    }
})


// 第四页实时用电
router.get('/api/electricity',ctx=>{
    const data=Mock.mock({
        grid:{
            left:'3%',
            right:'4%',
            bottom:'3%',
            containLabel:true
        },
        xAxis:[
            {
                type:'category',
                boundaryGap:false,
                data:['Mon','Tue','Wed','Thu','Fri','Sat','Sun']
            }
        ],
        yAxis:[
            {
                type:'value'
            }
        ],
        series:[
            {
                name:'Direct',
                type:'line',
                stack:'Total',
                smooth:true,
                showSymbol:false,
                areaStyle:{
                    color:'#ff0040'
                },
                emphasis:{
                    focus:'series'
                },
                data:['@integer(300,310)','@integer(330,360)','@integer(300,310)','@integer(330,340)','@integer(390,395)','@integer(330,340)','@integer(400,410)']
            }
        ]
    })
    ctx.body={
        code:200,
        msg:'调取成功',
        data
    }
})

// 第四页设备统计
router.get('/api/device',ctx=>{
    const data=Mock.mock({
        tooltip:{
            trigger:'item',
            formatter:'销量<br/>{b}: {c} ({d}%)'
        },
        legend:{
            orient:'vertical',
            left:20,
            top:20,
            data:['监控类','消防类','其他类'],
            textStyle:{
                color:'#fff'
            }
        },
        series:[{
            data:[
                    {
                        value:'@integer(230,240)',
                        name:'监控类'
                    },
                    {
                        value:'@integer(200,210)',
                        name:'消防类'
                    },
                    {
                        value:'@integer(330,340)',
                        name:'其他类'
                    }
            ]
        }]
    })
    ctx.body={
        code:200,
        msg:'请求成功',
        data
    }

})



// 监听端口号
app.listen(3001, () => {
console.log('server is running at http://localhost:3001')
})